package br.com.eduquiz.session;

import br.com.eduquiz.entity.*;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("respostaHome")
public class RespostaHome extends EntityHome<Resposta> {
	
	private static final long serialVersionUID = 6788251094118172848L;
	
	@In(create = true)
	private QuestaoHome questaoHome;
	
	@Override
	public String persist() {
		getInstance().setCliques(Long.valueOf(0));
		return super.persist();
	}

	public void setRespostaId(Long id) {
		setId(id);
	}

	public Long getRespostaId() {
		return (Long) getId();
	}

	@Override
	protected Resposta createInstance() {
		Resposta resposta = new Resposta();
		return resposta;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Questao questao = questaoHome.getDefinedInstance();
		if (questao != null) {
			getInstance().setQuestao(questao);
		}
	}

	public boolean isWired() {
		return true;
	}

	public Resposta getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

}
